<?php

if (!defined('PUBLIC_HTML'))
{
	exit;
}

/*
 * EXCEPTION CLASS EXTENTION
 */

class ErrorHandler extends PDOException 
{
	public function log_error($comments = '-')
	{
		$post = array(
			'message' 	=> $this->getMessage(),
			'file'		=> $this->getFile(),
			'line'		=> $this->getLine(),
			'comments'	=> $comments,
		);
		Database::sql_insert_row(TABLE_LOGS, $post);
		return true;
	}
	
	/**
	 * Generate and print an error message
	 * 
	 * @param string $comments		is an optional field where you can input the message the visitor gets to see.
	 * @param boolean $terminate	determines to either terminate the session immediatly or keep running the page.
	 */
	public function print_error($comments='-', $terminate=true)
	{
		$error_msg = 
		'
		<table style="width: 800px; border: 1px solid #BC0A24; font-family: Verdana; font-size: 10px; margin: 0 auto; border-radius:10px;" cellspacing="0">
			<tr style="height: 25px;">
				<th colspan="2" style="background-color: #BC0A24; border-radius:10px 10px 0 0; color:#FFFFFF;">Foutmelding</th>
			</tr>
			<tr style="height: 20px;">
				<td style="width: 200px; font-weight: bold; border-bottom: 1px solid #BC0A24;">Bericht:</td>
				<td style="width: 600px; border-bottom: 1px solid #BC0A24;">' . $comments . '</td>
			</tr>
			<tr style="height: 20px;">
				<td style="width: 200px; font-weight: bold; border-bottom: 1px solid #BC0A24;">Fout:</td>
				<td style="width: 600px; border-bottom: 1px solid #BC0A24;">' . $this->getMessage() . '</td>
			</tr>
			<tr style="height: 20px;">
				<td style="width: 200px; font-weight: bold; border-bottom: 1px solid #BC0A24;">Bestand:</td>
				<td style="width: 600px; border-bottom: 1px solid #BC0A24;">' . $this->getFile() . '</td>
			</tr>
			<tr style="height: 20px;">
				<td style="width: 200px; font-weight: bold; border-bottom: 1px solid #BC0A24;">Regel:</td>
				<td style="width: 600px; border-bottom: 1px solid #BC0A24;">' . $this->getLine() . '</td>
			</tr>
		</table>
		';
		
		if ($terminate)
		{
			die($error_msg);
		}
		else
		{
			echo $error_msg;
		}
	}
	
	public function pdo_error($comments='-', $message, $file, $line, $terminate=true)
	{
		$error_msg = 
		'
		<table style="width: 800px; border: 1px solid #BC0A24; font-family: Verdana; font-size: 10px; margin: 0 auto; border-radius:10px;" cellspacing="0">
			<tr style="height: 25px;">
				<th colspan="2" style="background-color: #BC0A24; border-radius:10px 10px 0 0; color:#FFFFFF;">Foutmelding</th>
			</tr>
			<tr style="height: 20px;">
				<td style="width: 200px; font-weight: bold; border-bottom: 1px solid #BC0A24;">Bericht:</td>
				<td style="width: 600px; border-bottom: 1px solid #BC0A24;">' . $comments . '</td>
			</tr>
			<tr style="height: 20px;">
				<td style="width: 200px; font-weight: bold; border-bottom: 1px solid #BC0A24;">Fout:</td>
				<td style="width: 600px; border-bottom: 1px solid #BC0A24;">' . $message . '</td>
			</tr>
			<tr style="height: 20px;">
				<td style="width: 200px; font-weight: bold; border-bottom: 1px solid #BC0A24;">Bestand:</td>
				<td style="width: 600px; border-bottom: 1px solid #BC0A24;">' . $file . '</td>
			</tr>
			<tr style="height: 20px;">
				<td style="width: 200px; font-weight: bold; border-bottom: 1px solid #BC0A24;">Regel:</td>
				<td style="width: 600px; border-bottom: 1px solid #BC0A24;">' . $line . '</td>
			</tr>
		</table>
		';
		
		if ($terminate)
		{
			die($error_msg);
		}
		else
		{
			echo $error_msg;
		}
	}
}

?>